﻿using System.Linq;

namespace CueMounter.DokanStructure
{
	class DokanDirectoryContainer : DokanDirectory
	{
		public DokanDirectory Directory { get; private set; }

		public DokanDirectoryContainer(DokanDirectory directory, string name = null)
		{
			Directory = directory;
			if(name != null)
			{
				Name = name;
			}
			else
			{
				Name = directory.Name;
			}
		}

		public override void Dispose()
		{
			Directory.Dispose();
		}

		public override DokanDirectory[] Directories
		{
			get
			{
				return new DokanDirectory[] { Directory };
			}
		}

		public override void MoveFile(string[] oldPath, string[] newPath, bool replace)
		{
			if(oldPath[0] == newPath[0])
			{
				Directory.MoveFile(oldPath.Skip(1).ToArray(), newPath.Skip(1).ToArray(), replace);
			}
			else
			{
				base.MoveFile(oldPath, newPath, replace);
			}
		}

		public override void MoveDirectory(string[] oldPath, string[] newPath, bool replace)
		{
			if(oldPath[0] == newPath[0])
			{
				Directory.MoveDirectory(oldPath.Skip(1).ToArray(), newPath.Skip(1).ToArray(), replace);
			}
			else
			{
				base.MoveDirectory(oldPath, newPath, replace);
			}
		}
	}
}
